package com.ja.openchat.viewmodels;

import android.app.Application;

import androidx.annotation.NonNull;

import com.zy.openchat.core.manager.TgEvent;
import com.zy.openchat.core.model.user.UserInfo;
import com.ja.openchat.ui.chat.MobileContactHomeActivity;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.base.BaseViewModel;


public class MobileContactActivityViewModel extends BaseViewModel {

    private MobileContactHomeActivity mContext;

    public MobileContactActivityViewModel(@NonNull Application application, BaseModel mRepository) {
        super(application);
    }


    public void setContext(MobileContactHomeActivity mContext) {
        this.mContext = mContext;
    }



    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onTgEvent(final TgEvent tg_event) {
        switch (tg_event.event) {
            case EUser_Td_Contact_Photo_Ok:
                mContext.contactListAdapter.notifyDataSetChanged();
                break;
            case EUser_Td_UpdateContactInfo:
                mContext.requestContacts();
                break;
            case EUser_Td_AddNewContactInfo: {
                UserInfo user = (UserInfo) tg_event.data;
                if (user.is_contact) {
                    mContext.requestContacts();
                }
            }
            break;
        }
    }


}
